﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class CTGIAOLYDAO:IData<CTGIAOLY> 
 	{
		public CTGIAOLYDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref CTGIAOLY item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + CTGIAOLY.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_CTGIAOLY", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + CTGIAOLY.c_NVID, item.NVID), new SqlParameter("@" + CTGIAOLY.c_GLID, item.GLID),
				 new SqlParameter("@" + CTGIAOLY.c_NAM, item.NAM), new SqlParameter("@" + CTGIAOLY.c_NoiCapBang, item.NoiCapBang));
			if(t == 0)
				item.ID = Convert.ToInt64(obj);
			return i;
		}

		public override CTGIAOLY GetItem(IDataReader dr)
		{
			CTGIAOLY obj = new CTGIAOLY();
			obj.ID = Convert.ToInt64(dr[CTGIAOLY.c_ID]);
			obj.NVID = Convert.ToInt64(dr[CTGIAOLY.c_NVID]);
			obj.GLID = Convert.ToInt64(dr[CTGIAOLY.c_GLID]);
			obj.NAM = Convert.ToInt32(dr[CTGIAOLY.c_NAM]);
			obj.NoiCapBang = Convert.ToString(dr[CTGIAOLY.c_NoiCapBang]);
			return obj;
		}

		public override List<CTGIAOLY> GetAll()
		{
			return GetAll("sp_GetAllCTGIAOLY", CommandType.StoredProcedure);
		}

		public override CTGIAOLY GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.ID == Convert.ToInt64(id));
		}
		public override CTGIAOLY GetItemById(CTGIAOLY item){
			throw new NotImplementedException();
		}

	}

 }
